package servlet;

import model.Product;
import model.Order;
import model.User;
import service.OrderService;
import service.ProductService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;
import java.util.List;

@WebServlet(name = "order_list",urlPatterns = "/order_list")
public class OrderListServlet extends HttpServlet {
    private ProductService pService = new ProductService();
    private OrderService oService = new OrderService();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Order o = null;
        User user = (User) request.getSession().getAttribute("user");
        if (user == null) {
            request.setAttribute("failMsg", "请先登录！");
            request.getRequestDispatcher("/user_login.jsp").forward(request, response);
            return;
        }
        //更新上下文中orderList的数据
        List<Order> orderList= oService.selectAllByReceiverId(user.getId());
        this.getServletContext().removeAttribute("orderList");
        this.getServletContext().setAttribute("orderList",orderList);
        //已下架的orderlist
        List<Order> orderCompletedList= oService.selectCompeletedByReceiverId(user.getId());
        this.getServletContext().removeAttribute("orderCompletedList");
        this.getServletContext().setAttribute("orderCompletedList",orderCompletedList);
        //还未完成的orderlist
        List<Order> orderUnFinishedList= oService.selectUnFinishedByReceiverId(user.getId());
        this.getServletContext().removeAttribute("orderUnFinishedList");
        this.getServletContext().setAttribute("orderUnFinishedList",orderUnFinishedList);
        //获取商品id
//        int goodsid = Integer.parseInt(request.getParameter("goodsid"));
//        request.setAttribute("gcs", "商品发布成功！");
        request.getRequestDispatcher("/my_publish.jsp").forward(request, response);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
